﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BYUStock.Comman
{
    public struct Candle
    {
        public float High { get; set; }
        public float Low { get; set; }
        public float Open { get; set; }
        public float Close { get; set; }

        public DateTime Start { get; set; }
        public TimeSpan Span { get; set; }

        public float VOL { get; set; }

        public bool IsVolRised(Candle candle, float trMin = 1, float trMax = 1)
        {
            if (trMin < 1 || trMax < 1 || (trMin > 1 && trMax == 1)) throw new ArgumentOutOfRangeException("条件参数非法");
            if (trMin == 1 && trMax == 1) return candle.VOL > VOL;
            if (trMin == 1) return candle.VOL > VOL && candle.VOL / VOL <= trMax;
            if (trMax == 1) return candle.VOL > VOL && candle.VOL / VOL >= trMin;
            return candle.VOL > VOL && candle.VOL / VOL >= trMin && candle.VOL / VOL <= trMax;
        }

        public bool IsVolFell(Candle candle, float trMin = 0, float trMax = 1)
        {
            if (trMin < 0 || trMin > 1 || trMax < 0 || trMax > 1 || trMin > trMax) throw new ArgumentOutOfRangeException("条件参数非法");
            if (trMin == 0 && trMax == 1) return candle.VOL < VOL;
            if (trMin == 0) return candle.VOL < VOL && candle.VOL / VOL <= trMax;
            if (trMax == 1) return candle.VOL < VOL && candle.VOL / VOL >= trMin;
            return candle.VOL < VOL && candle.VOL / VOL >= trMin && candle.VOL / VOL <= trMax;
        }

        public bool IsPriceRised(Candle candle, float trMin = 1, float trMax = 1)
        {
            if (trMin < 1 || trMax < 1 || (trMin > 1 && trMax == 1)) throw new ArgumentOutOfRangeException("条件参数非法");
            if (trMin == 1 && trMax == 1) return candle.Close > Close;
            if (trMin == 1) return candle.Close > Close && candle.Close / Close <= trMax;
            if (trMax == 1) return candle.Close > Close && candle.Close / Close >= trMin;
            return candle.Close > Close && candle.Close / Close >= trMin && candle.Close / Close <= trMax;
        }

        public bool IsPriceFell(Candle candle, float trMin = 0, float trMax = 1)
        {
            if (trMin < 0 || trMin > 1 || trMax < 0 || trMax > 1 || trMin > trMax) throw new ArgumentOutOfRangeException("条件参数非法");
            if (trMin == 0 && trMax == 1) return candle.Close < Close;
            if (trMin == 0) return candle.Close < Close && candle.Close / Close <= trMax;
            if (trMax == 1) return candle.Close < Close && candle.Close / Close >= trMin;
            return candle.Close < Close && candle.Close / Close >= trMin && candle.Close / Close <= trMax;
        }
    }
}
